package com.czwj.service.impl;

import java.io.File;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.czwj.dao.AttachmentMapper;
import com.czwj.dao.AttachmentRelyMapper;
import com.czwj.entities.Attachment;
import com.czwj.service.AttachmentService;

@Service
public class AttachmentServiceImpl implements AttachmentService {

	@Resource
	AttachmentMapper mapper;
	@Resource
	AttachmentRelyMapper rmapper;
	@Override
	public int delete(int id) {
		Attachment attachment = mapper.selectByPrimaryKey(id);
		File file = new File(attachment.getPath());
		if(file.exists()){
			file.delete();
		}
		int count = mapper.deleteByPrimaryKey(id);
		count+= rmapper.deleteByAttachmentid(id);
		return count;
	}
	@Override
	public Attachment selectByPrimaryKey(int id) {
		// TODO Auto-generated method stub
		return this.mapper.selectByPrimaryKey(id);
	}

}
